from  random import choice

cave_numbers=range(0,20)
caves=[]
for i in cave_numbers:
    caves.append([])
#生成洞穴列表
for i in cave_numbers:
    for j in range(3):
        passage_to=choice(cave_numbers)
        caves[i].append(passage_to)
print caves
#为每个洞穴联通三个其他洞穴
wumpus_location=choice(cave_numbers)
player_location=choice(cave_numbers)
while player_location==wumpus_location:
    player_location=choice(cave_numbers)

print "welcome to hunt the wumpus"
print "you can see",len(cave_numbers),"caves"
print "to play,just type the number"
print "of the cave you wish to enter next"

while True:
    print "you are in cave",player_location
    print "From here,you can see caves:",caves[player_location]
    if wumpus_location in caves[player_location]:
        print "i smell a wumpus!"
#打印玩家所在洞穴位置
    print "which cave next?"
    player__input=raw_input(">")
    if(not player__input.isdigit() or int(player__input) not in cave_numbers):
        print player__input,"is not a cave!"

    else:
        player_location=int(player__input)
        if player_location==wumpus_location:
            print "you get eaten by a wumpus!"
            break